package com.homework.api_email.services.impl;

import com.homework.interface_email.services.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.apache.dubbo.config.annotation.Service;

@Service
public class EmailServiceImpl implements EmailService {
    @Autowired
    private JavaMailSender mailSender;

    /**
     *
     * @param email
     */
    public boolean send(String email, String code)  {
        //1.邮件发送
        try {
            //创建SimpleMailMessage对象
            SimpleMailMessage message = new SimpleMailMessage();
            //邮件发送人
            message.setFrom("3116818769@qq.com");
            //邮件接收人
            message.setTo(email);
            //邮件主题
            message.setSubject("验证码");
            //邮件内容
            message.setText("您的验证码是: " + code + ", 1分钟内有效");
            //发送邮件
            mailSender.send(message);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return false;
        }

        return true;
    }

}
